Data Types in JavaScript 您所在的位置:网站首页 JavaScript Data Types Data Types in JavaScript

Data Types in JavaScript

2024-06-17 16:38| 来源: 网络整理| 查看: 265

There are seven data types in JavaScript, six simple (primitive) and one complex.

Simple data types:

Undefined Null Boolean Number String Symbol (new added in ES6)

Complex data type:

Object. The typeof operator

JavaScript is loosely typed and variables are defined without declaring data type. To determine the data type, the typeof operator should be used. The typeof operator returns string denoting the type of variable being operand. Following strings can be returned:

“undefined” – if the value is undefined, “boolean” – if the value is false or true, “string” – if the value is a string, “number” – if the value is a number, “object” – if the value is an object (including arrays) or null, “function” – if the value is a function. var a = "one", b = 2; console.log(typeof a); // string console.log(typeof b); // number

 

Data types meaning

The undefined value indicates that expected value is not defined and is only one value of the undefined type.

The null value is considered to be an empty object reference and is only one value of the null type.

Booleans, strings and numbers are other primitive values. Boolean represents logical truth and falsehood, string is sequence of Unicode characters, number simply represents all numbers.

Object is a collection of properties, where each property has a name and a value. Ordinary objects are unordered collections of named values. An array is special kind of object, which contains an ordered collection of numbered values. A function is another special kind of object which has executable code associated with it. Functions in JavaScript are true values and can be treated like regular objects.

No Comments Reply cancel reply


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有